﻿using System.ComponentModel.Composition;
using System.Web.Mvc;
using LM_Shop.Models.Auctions;
using LM_Shop.Services.Auction;

namespace LM_Shop.Controllers
{
    [Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class AuctionController : Controller
    {
        //
        // GET: /Auction/

        //do zrobienia IoC : http://blogs.realdolmen.com/experts/2012/08/31/mef-in-asp-net-mvc-4-and-webapi/ 
        [Import]
        private IAuctionService _auctionService;
        
        public ActionResult AuctionDetails(int id)
        {
            
            var result = _auctionService.GetDetails(id);

            return View(result);
        }

        public ActionResult AuctionList()
        {
            var result = _auctionService.GetAuctionList();
            return View(result);
        }

        //[HttpPost]
        public ActionResult Buy(AuctionModel model)
        {
            if (ModelState.IsValid)
            {
                _auctionService.Buy(model.Id);
                return this.RedirectToAction("AuctionDetails", new { Id = model.Id });
            }
            return null;
        }
    }
}
